﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;

namespace MPMovieCatalog.Configuration
{
    public abstract class PropertySection : ConfigurationSection
    {
        public PropertySection() { }

        public void SetProperty(string name, string value)
        {
            PropertyElement property = (PropertyElement)base[name];
            if (property == null)
            {
                property = new PropertyElement();
                base[name] = property;
            }
            property.Value = value;
        }


        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            if (reader.ReadToDescendant("property"))
            {
                do
                {
                    base[reader.GetAttribute("name")] = new PropertyElement(reader.ReadElementContentAsString());
                } while (reader.ReadToNextSibling("property"));
            }
        }
    }
}
